clear
cap log close

cd "D:\Dropbox\Work\Research\CreditCardABSRewrite\Draft\ReplicationFiles\Tab_8"

local today = "`c(current_date)'"
log using "Table_08_Log.log", text append


import delimited "Data_Table_08.csv"

* generate ts index
gen t = _n
tsset t

* generate indicators for subperiods
generate pre=1 if year<2007
generate cri=1 if year>2006 & year<2010
generate post=1 if year>2009 & year<2020


label variable driskprem_a   "DeltaRiskPrem_A"
label variable driskprem_b   "DeltaRiskPrem_B"
label variable driskprem_c   "DeltaRiskPrem_B"
label variable dcapratio   "DeltaTier1"
label variable dhkmlevfac   "DeltaLeverage"
label variable dedfpremium   "DeltaTurnOfYear"
label variable dcapratio_lag   "DeltaTier1_lag"
label variable dhkmlevfac_lag   "DeltaLeverage_lag"
label variable dedfpremium_lag   "DeltaTurnOfYear_lag"


* Table 8
*****************
* A Tranche
* All
regress driskprem_a dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag
loc AdjR2 = e(r2_a)
newey2 driskprem_a dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag, lag(2) force
outreg2 using Tab8_A, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("All") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word replace
* 2000-2006
regress driskprem_a dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if pre==1
loc AdjR2 = e(r2_a)
newey2 driskprem_a dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if pre==1, lag(2) force
outreg2 using Tab8_A, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("2000-2006") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word 
* 2007-2009
regress driskprem_a dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if cri==1
loc AdjR2 = e(r2_a)
newey2 driskprem_a dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if cri==1, lag(2) force
outreg2 using Tab8_A, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("2007-2009") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word 
* 2010-2020
regress driskprem_a dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if post==1
loc AdjR2 = e(r2_a)
newey2 driskprem_a dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if post==1, lag(2) force
outreg2 using Tab8_A, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("A Tranche") ctitle("2010-2020") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word 


*******************
* B Tranche
* All
regress driskprem_b dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag
loc AdjR2 = e(r2_a)
newey2 driskprem_b dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag, lag(2) force
outreg2 using Tab8_B, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("All")  drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word replace
* 2000-2006
regress driskprem_b dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if pre==1
loc AdjR2 = e(r2_a)
newey2 driskprem_b dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if pre==1, lag(2) force
outreg2 using Tab8_B, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("2000-2006") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word 
* 2007-2009
regress driskprem_b dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if cri==1
loc AdjR2 = e(r2_a)
newey2 driskprem_b dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if cri==1, lag(2) force
outreg2 using Tab8_B, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("2007-2009") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word 
* 2010-2020
regress driskprem_b dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if post==1
loc AdjR2 = e(r2_a)
newey2 driskprem_b dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if post==1, lag(2) force
outreg2 using Tab8_B, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("B Tranche") ctitle("2010-2020") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word 


*******************
* C Tranche
* All
regress driskprem_c dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag
loc AdjR2 = e(r2_a)
newey2 driskprem_c dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag, lag(2) force
outreg2 using Tab8_C, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("All") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word replace
* 2000-2006
regress driskprem_c dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if pre==1
loc AdjR2 = e(r2_a)
newey2 driskprem_c dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if pre==1, lag(2) force
outreg2 using Tab8_C, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("2000-2006") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word 
* 2007-2009
regress driskprem_c dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if cri==1
loc AdjR2 = e(r2_a)
newey2 driskprem_c dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if cri==1, lag(2) force
outreg2 using Tab8_C, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("2007-2009") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word 
* 2010-2020
regress driskprem_c dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if post==1
loc AdjR2 = e(r2_a)
newey2 driskprem_c dcapratio dhkmlevfac dedfpremium dcapratio_lag dhkmlevfac_lag dedfpremium_lag if post==1, lag(2) force
outreg2 using Tab8_C, stats(coef tstat) noaster noparen  addstat(AdjR2, `AdjR2') title("C Tranche") ctitle("2010-2020") drop(driskprem*) bdec(4) bfmt(f) tdec(2) tfmt(f) rdec(3) rfmt(f) label word 

log close